﻿
using System;
using System.Data;
using Besture.Common;
using Besture.Dal;
using Besture.Model;

namespace Besture.Bll
{
    public class ModulesDac : BaseFacade
    {
        private readonly ModulesDal excuteDal = new ModulesDal();

        /// <summary>
        /// ���
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(ModulesModel model)
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                int lsRecord = 0;
                lsRecord = excuteDal.Add(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }

        /// <summary>
        /// �޸�
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(ModulesModel model)
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                int lsRecord = 0;
                lsRecord = excuteDal.Update(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }



        /// <summary>
        /// ����id��ȡ��������
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ModulesModel GetModel(int id)
        {
            try
            {
                CreateConnection();
                return excuteDal.GetModel(id);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetDataTable()
        {
            try
            {
                CreateConnection();
                return excuteDal.GetDataTable();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }

        /// <summary>
        /// ����ɾ��
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            try
            {
                CreateConnection();
                return excuteDal.Delete(id);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }


        /// <summary>
        /// ����ɾ��
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        public int DeleteList(string ids)
        {
            try
            {
                CreateConnection();
                return excuteDal.DeleteList(ids);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }
    }
}
